package com.test.web.controller.vue;

import com.github.pagehelper.PageInfo;
import com.he.core.ResultT;
import com.he.web.annotation.NeedToken;
import com.test.web.controller.base.BaseController;
import com.test.web.entity.Role;
import com.test.web.service.RoleService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author heyanjing
 * date:2020-06-09 2020/6/9:22:54
 */
@Slf4j
@AllArgsConstructor
@RestController
public class RoleController extends BaseController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/role/insert")
    public ResultT login(@RequestBody Role role) throws Exception {
        return roleService.insert(role);
    }

    @GetMapping("/role/get")
    public ResultT<Role> get(String roleId) throws Exception {
        return roleService.get(roleId);
    }

    @PostMapping("/role/update")
    public ResultT update(@RequestBody Role role) throws Exception {
        return roleService.update(role);
    }

    @GetMapping("/role/delete")
    public ResultT delete(String roleId) throws Exception {
        return roleService.delete(roleId);
    }

    @NeedToken(false)
    @GetMapping("/role/find")
    public ResultT<PageInfo<Role>> find(String search, String state, String sort, Integer pageIndex, Integer pageSize) throws Exception {
        return roleService.find(search, state, sort, pageIndex, pageSize);
    }

}
